<html>
<head>
    <title>吉垚物业后台管理系统</title>
    <meta charset="utf-8">
    <link rel="shortcut icon" th:href="./images/favicon.ico" type="image/x-icon">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <!-- 引入css -->
    <link rel="stylesheet" href="./css/plugins/font-awesome-4.7.0/css/font-awesome.min.css"  media="all">
    <link rel="stylesheet" href="./lib/layui-v2.3.0/css/layui.css"  media="all">
    <link rel="stylesheet" href="./css/main.css"  media="all">
    <link rel="stylesheet" href="./css/bootstrap.min.css">
</head>
<body>
<div class="">
<!--    <form action="#">-->
		  <div class="layui-form-item">
			<label class="layui-form-label">原密码</label>
			<div class="layui-input-inline">
			  <input type="text" name="passwordDB" id="passwordDB" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
                <div id="pdw"></div>
			</div>
		  </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="text" name="password" id="password" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
                <div id="pw"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input type="text" name="password2" id="password2" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
                <div id="pw2"></div>
            </div>
        </div>
        <hr>
        <div class="layui-form-item timo-finally">
            <button class="layui-btn " onclick="updateUserPass()"><i class="fa fa-check-circle"></i> 保存</button>
            <button class="layui-btn btn-secondary close-popup" id="close"><i class="fa fa-times-circle"></i> 关闭</button>
        </div>
<!--    </form>-->
</div>
<script src="./lib/layui-v2.3.0/layui.js" charset="utf-8"></script>
<script src="./js/main.js" charset="utf-8"></script>
<script src="js/plugins/jquery-3.3.1.min.js"></script>
<script src="js/checkToken.js"></script>
</body>
<script type="text/javascript">
    // var category=window.location.search;
    // //截取，获取获得category的具体值
    // var typeid = category.substring(category.lastIndexOf('=')+1, category.length);
    // console.log(category);
    // console.log(cateval);
    // var userid=sessionStorage.getItem('userid');
    var username=sessionStorage.getItem('username');

    function updateUserPass() {
        var passwordDB=$('#passwordDB').val();
        var password=$('#password').val();
        var password2=$('#password2').val();
        $('#pdw').empty();
        $('#pw').empty();
        $('#pw2').empty();
        if (passwordDB=='') {
            $('#pdw').append('<span style="color: #FD482C">原密码不能为空</span>')
            return;
        }
        if (password=='') {
            $('#pw').append('<span style="color: #FD482C">新密码不能为空</span>')
            return;
        }
        if (password.length<6){
            $('#pw').append('<span style="color: #FD482C">新密码长度不能小于6位</span>')
            return;
        }
        if (password2!=password) {
            $('#pw2').append('<span style="color: #FD482C">确认密码与新密码不一致</span>')
            return;
        }
        var flag=0;
        $.ajax({
            url:'http://localhost:8081/admin/login.do?name='+username+'&password='+passwordDB,
            async:false,
            success:function (data) {
                if (data.resMsg==undefined)
                    data=JSON.parse(data);
                if (data.resMsg!='登陆成功'){
                    console.log('登录失败')
                    $('#pdw').append('<span style="color: #FD482C">原密码错误</span>')
                    flag=-1;
                }
            }
        })
        if (flag==-1)
            return;
        $.ajax({
            url:'http://localhost:8081/admin/updateUserPass.do?password='+password,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (data) {
                checkToken(data)
                if (data.resMsg!='更新失败'){
                    alert('修改成功');
                    top.location.reload();
                    this.close();
                }else{
                    alert('更新失败');
                }
            }
        })
    }

</script>
</html>